package com.open.capacity.db.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.model.DB;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.db.service.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/db")
public class DBController {

    @Autowired
    DBService dbService;

    @GetMapping("/getDBList")
    public PageResult getDBList(@RequestParam Map map){
        try {
            return dbService.getDBList(map);
        }catch (ControllerException e){
            throw new ControllerException(e);
        }
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody DB db){
        try {
            return dbService.saveOrUpdate(db);
        }catch (ControllerException e){
            throw new ControllerException(e);
        }
    }
    @PostMapping("/deleteDB")
    public Result deleteDB(@RequestParam Integer dbId){
        try {
            return dbService.deleteDB(dbId);
        }catch (ControllerException e){
            throw new ControllerException(e);
        }
    }

    @PostMapping("/upload")
    public Result upload(MultipartFile file){
        return Result.succeed("success");
    }

}
